package cn.itcast.demo;

import cn.itcast.domain.Orders;
import cn.itcast.mapper.OrdersMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.io.InputStream;
import java.util.List;

public class OrdersDemo {
    private SqlSession sqlSession = null;
    private OrdersMapper mapper = null;
    @Before
    public  void  before() throws Exception{
        //读取mybatis核心配置文件
        InputStream is = Resources.getResourceAsStream("SqlConfig.xml");
        SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(is);
        sqlSession = sessionFactory.openSession();
        mapper = sqlSession.getMapper(OrdersMapper.class);
    }

    @After
    public void after(){
        sqlSession.commit();
        sqlSession.close();
    }

    @Test
    public void findOrdersAndUsername(){
        List<Orders> ordersList = mapper.findAll();
        for (Orders orders : ordersList) {
            //订单信息
            System.out.println(orders);
        }
    }

}

















